package com.fengfeng.view.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.fengfeng.http.HttpCallback;
import com.fengfeng.http.HttpUrlConstant;
import com.fengfeng.http.HttpUtils;
import com.fengfeng.sdk.R;
import com.fengfeng.sdk.login.LoginManager;
import com.fengfeng.sdk.model.UserInfo;
import java.io.IOException;
import java.util.HashMap;
import org.json.JSONObject;

public class RegisterDialog extends BaseDialog {

    /**
     * 显示的账号登录文本
     */
    private TextView text1;

    /**
     * 显示账号和密码输入框的文本
     */
    private EditText editAccount, editPassword;

    /**
     * 显示注册按钮
     */
    private Button registerBtn;

    private Activity mActivity;


    public RegisterDialog(@NonNull Activity context) {
        super(context, R.style.CustomDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.register_dialog_layout);
        //按空白处不能取消动画
        setCanceledOnTouchOutside(false);
        //初始化界面控件
        initView();//看到没有，oppo给你接的aar,就是这么生成的。rebuild,它就会把每个lib模块生成一个aar,
        // app模块则不会生成，懂没
        //初始化界面控件的事件
        initEvent();
    }

    private void initView() {
        text1 = findViewById(R.id.tv1);
        editAccount = findViewById(R.id.ed_ac);
        editPassword = findViewById(R.id.ed_ps);
        registerBtn = findViewById(R.id.btn);
    }

    private void initEvent() {
        /**
         * 在注册按钮中执行相应的逻辑
         * 接入注册接口进行请求,返回数据
         */
        registerBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String account = editAccount.getText().toString();
                String password = editPassword.getText().toString();
                UserInfo userInfo = new UserInfo("", account, password);
                LoginManager.getInstance().registerRequest(userInfo);
            }
        });


    }

    @Override
    public void show() {
        super.show();
    }
}
